﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EnterpriseFund.Common;

namespace EnterpriseFund.Controllers
{
        [OutputCache(Duration = 0, VaryByParam = "none")]   
    public class RejectTaxController : AdminBaseController
    {
        //
        // GET: /FinanceProp/
        /// <summary>
        /// 代码维护主页
        /// </summary>
        /// <returns>视图</returns>
        [AuthorityActionFilter("m_RejectTax", Order = 1)]
        [LogPageActionFilter("剔除税种定义", Order = 2)]
        public ActionResult Index()
        {
            List<Model.RejectTax> codeNameList = new List<Model.RejectTax>();
            ViewData["blcode"] = true;
            BLL.RejectTax codeNameBll = new BLL.RejectTax();
            codeNameList = codeNameBll.GetModelList("FYear=" + OperateSession.get(Common.GlobalConstant.PARAM_SYSYEAR));
            return View(codeNameList);
        }

        /// <summary>
        /// 编码树相关调用方法 主要用于刷新
        /// </summary>
        /// <returns>视图</returns>
        public ActionResult RejectTaxListPartial()
        {
            BLL.RejectTax codeNameBll = new BLL.RejectTax();
            List<Model.RejectTax> codeNameList = new List<Model.RejectTax>();
            codeNameList = codeNameBll.GetModelList("FYear=" + OperateSession.get(Common.GlobalConstant.PARAM_SYSYEAR));
            ViewData["blcode"] = true;
            return PartialView("RejectTaxListPartial", codeNameList);
        }

        /// <summary>
        /// 编码增加修改
        /// </summary>
        /// <param name="codeClsNo">编码类别编码 必须有具体值</param>
        /// <param name="codeNo">编码</param>
        /// <returns>视图</returns>
        public ActionResult RejectTaxEdit(string rejectTaxNo)
        {
            Model.RejectTax codeNameObj = new Model.RejectTax();
            ViewData["blcodeNo"] = true;
            if (null != rejectTaxNo)
            {
                rejectTaxNo = Fetch.estimateString(rejectTaxNo, CheckGetEnum.Safety);
                BLL.RejectTax codeNameBll = new BLL.RejectTax();
                codeNameObj = codeNameBll.GetModel(rejectTaxNo, decimal.Parse(OperateSession.get(Common.GlobalConstant.PARAM_SYSYEAR)));
                if (null == codeNameObj)
                {
                    codeNameObj = new Model.RejectTax();
                }
                else
                {
                    ViewData["blcodeNo"] = false;
                }
            }

            return View(codeNameObj);
        }


        /// <summary>
        /// 编码保存
        /// </summary>
        /// <param name="codeNo">编码编号</param>
        /// <param name="codeName">编码名字</param>
        /// <param name="codeClsNo">编码类别编码</param>
        /// <param name="isAdd">是否添加true添加，false修改</param>
        /// <returns>是否添加成功</returns>
        public string RejectTaxSave(string rejectTaxNo, string rejectEnterpriseNote, string rejectEnterpriseSQL, string rejectTaxNote, string rejectTaxSQL, bool isAdd)
        {
            string str = string.Empty;

            rejectTaxNo = Fetch.estimateString(rejectTaxNo, CheckGetEnum.Safety);
            rejectEnterpriseNote = Fetch.estimateString(rejectEnterpriseNote, CheckGetEnum.Safety);
            rejectTaxNote = Fetch.estimateString(rejectTaxNote, CheckGetEnum.Safety);

            BLL.RejectTax codeNameBll = new BLL.RejectTax();
            if (isAdd)//增加时判断编码是否已存在
            {
                if (codeNameBll.Exists(rejectTaxNo, decimal.Parse(OperateSession.get(Common.GlobalConstant.PARAM_SYSYEAR))))
                {
                    return "exists";
                }
            }

            Model.RejectTax codeNameObj = new Model.RejectTax();
            codeNameObj.FRejectTaxNo = rejectTaxNo;
            codeNameObj.FRejectEnterpriseNote = rejectEnterpriseNote;
            codeNameObj.FRejectEnterpriseSQL = rejectEnterpriseSQL;
            codeNameObj.FRejectTaxNote = rejectTaxNote;
            codeNameObj.FRejectTaxSQL = rejectTaxSQL;
            codeNameObj.FYear = decimal.Parse(OperateSession.get(Common.GlobalConstant.PARAM_SYSYEAR));

            try
            {
                if (isAdd)
                {
                    codeNameBll.Add(codeNameObj);
                }
                else
                {
                    codeNameBll.Update(codeNameObj);
                }
                str = "ok";

            }
            catch (Exception)
            {

                str = "error";
            }

            return str;
        }


        /// <summary>
        /// 删除编码数据
        /// </summary>
        /// <param name="codeNo">编码编号</param>
        /// <param name="codeClsNO">编码类别编码</param>
        /// <returns>是否删除成功</returns>
        public string DelRejectTax(string rejectTaxNo)
        {
            string str = string.Empty;
            if (null != rejectTaxNo)
            {
                rejectTaxNo = Fetch.estimateString(rejectTaxNo, CheckGetEnum.Safety);
                BLL.RejectTax codeNameBll = new BLL.RejectTax();
                try
                {
                    codeNameBll.Delete(rejectTaxNo, decimal.Parse(OperateSession.get(Common.GlobalConstant.PARAM_SYSYEAR)));
                    str = "ok";
                }
                catch (Exception)
                {
                    str = "error";
                }
            }
            return str;
        }
    }
}
